package com.ucomm.talent.adapter;

import java.util.ArrayList;
import java.util.List;

import com.ucomm.talent.AppConfig;
import com.ucomm.talent.R;
import com.ucomm.talent.model.JobOfferInfo;


import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class JobOffersListAdapter extends BaseAdapter{
	
	private LayoutInflater mInflater;
	//数据
	private ArrayList<JobOfferInfo> mData;
	
	public JobOffersListAdapter(Context context, ArrayList<JobOfferInfo> mData){
	        this.mInflater = LayoutInflater.from(context);
	        this.mData = mData;
	    }
	
	public ArrayList<JobOfferInfo> getmData() {
		return mData;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size();
	}
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mData.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
	        if (convertView == null) {

	            holder=new ViewHolder();

	            convertView = mInflater.inflate(R.layout.custom_list_item, null);
	            holder.job_name = (TextView)convertView.findViewById(R.id.job_name);//职位名
	            holder.certified_company = (TextView)convertView.findViewById(R.id.certified_company);
	            holder.approval = (TextView)convertView.findViewById(R.id.approval);
	            holder.work_category = (TextView)convertView.findViewById(R.id.work_category);//职位类别
	            holder.work_location = (TextView) convertView.findViewById(R.id.work_location);//工作地点
	            holder.work_treatment = (TextView) convertView.findViewById(R.id.work_treatment);//待遇
	            holder.work_enterprise = (TextView) convertView.findViewById(R.id.work_enterprise);//公司名
	            convertView.setTag(holder);

	        }else {
	            holder = (ViewHolder)convertView.getTag();
	        }
	        JobOfferInfo info = mData.get(position);
	        holder.job_name.setText(info.getName());
	        String work_category = null;
	        String work_location = null;
	        String work_treatment = null;
	        String work_enterprise = null;
	        String address = null;
	        if(AppConfig.jobMap.size() != 0 && AppConfig.cityMap.size() != 0 && AppConfig.comMap.size() != 0 && 
	        		AppConfig.industryMap.size() != 0 && AppConfig.userMap.size() != 0){
	        	work_category = AppConfig.jobMap.get(info.getClassification());
	        	work_location = AppConfig.cityMap.get(info.getProvinceId()+"")+AppConfig.cityMap.get(info.getCityId()+"");
	        	work_treatment = AppConfig.comMap.get(info.getSalary()+"");
	        }
	        holder.work_category.setText(work_category);
//	        address = info.getProvinceId()+info.getCityId()+"";
	        holder.work_location.setText(work_location);
	        holder.work_treatment.setText(work_treatment);
	        if(AppConfig.comName.size()!=0){
	        	work_enterprise = AppConfig.comName.get(info.getCompanyId()+"");
	        }
	        holder.work_enterprise.setText(work_enterprise);

	        return convertView;
	}
	 final class ViewHolder{
	        public TextView job_name;
	        public TextView certified_company;
	        public TextView approval;
	        public TextView work_category;
	        public TextView work_location;
	        public TextView work_enterprise;
	        public TextView work_treatment;
		}
}
